#!/usr/bin/env python
# coding=utf-8
import RPi.GPIO as GPIO
import time

class Mq135(object):
    channel = 7
    flag = True

    def action(self, channel):
        self.flag = False

    def returnAirQuality(self):
        #初始化
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self.channel, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

        #检测触发沿
        GPIO.add_event_detect(self.channel, GPIO.RISING)
        GPIO.add_event_callback(self.channel, self.action)

        try:
            for i in range(10):
                time.sleep(0.5)
        except KeyboardInterrupt:
            GPIO.cleanup()

        return self.flag

if __name__ == "__main__":
    mq135 = Mq135()
    print(mq135.returnAirQuality())



        
